<!--
 * @Description: 泵送费用
 * @Autor: wangwangwang
 * @Date: 2021-01-21 12:18:15
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-12-30 15:44:52
-->
<template>
  <div>
    <el-dialog v-dialogDrag :visible.sync="dialog" width="1300px" :close-on-click-modal="false" :before-close="reset">
      <span slot="title" class="dialog-title">工程调价</span>
      <div>
        <div class="dialoginfo-title-bg">
          <div class="dialoginfo-title1">
            <template v-for="item in checknavlist">
              <div :key="item.id" :class="checkindex ==item.id ? 'active' : 'none'" @click="checkindex=item.id">
                <div>{{item.name}}</div>
              </div>
            </template>
          </div>
        </div>
        <div style="height:530px;padding:20px 0" class="scroll">
          <div v-show="checkindex==2">
            <span>小于{{fromDate2.chargeStandard}}方每车，不足部分按</span>
            <el-input 
              v-model="fromDate2.money" 
              v-input-limit="(value) => (String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/) ? String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/)[0] : '')" 
              style="width:160px;margin:0 20px" 
              placeholder="请输入" 
              type="Number" 
              @blur="save(fromDate2,3)"> </el-input>
            <span>元/方，计算运输费用补差。</span>
          </div>
          <!-- 信息调价 -->
          <div v-show="checkindex==0">
            <div>
              <el-button size="small" class="bottom_all" @click="open('dialog1')">
                信息调价
              </el-button>
            </div>
            <div style="padding-top: 20px">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="fromDate01" tooltip-effect="dark">
                <el-table-column align="center" label="强度等级" prop="itemName"></el-table-column>
                <el-table-column align="center" label="预计量（方）">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.chargeStandard" style="width:100%" @blur="save(scope.row)"></el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="初始合同价格">
                  <template slot-scope="scope">
                    <el-input 
                      v-model="scope.row.money"
                      v-input-limit="(value) => (String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/) ? String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/)[0] : '')" 
                      style="width:100%" 
                      type="Number" 
                      @blur="save(scope.row)">
                    </el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="备注" prop="remark">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.remark" style="width:100%" @blur="save(scope.row)"></el-input>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="最新调整价格" prop="newMoney"></el-table-column>
                <el-table-column align="center" label="操作" width="250">
                  <template slot-scope="scope">
                    <el-button size="mini" class="bottom_all_two" @click="open('dialog2',scope.row)">协商调价</el-button>
                    <el-button size="mini" class="bottom_all_two" style="margin-left: 18px" @click="open('dialog3',scope.row)">调价记录</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div style="padding-top: 20px">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="fromDate02" tooltip-effect="dark">
                <el-table-column align="center" label="性能等级" prop="itemName"></el-table-column>
                <el-table-column align="center" label="规格/类型">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.chargeStandard" style="width:100%" @blur="save(scope.row)"></el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="初始合同价格">
                  <template slot-scope="scope">
                    <el-input 
                      v-model="scope.row.money"
                      v-input-limit="(value) => (String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/) ? String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/)[0] : '')" 
                      style="width:100%" 
                      type="Number" 
                      @blur="save(scope.row)">
                    </el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="备注" prop="remark">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.remark" style="width:100%" @blur="save(scope.row)"></el-input>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="最新调整价格" prop="newMoney"></el-table-column>
                <el-table-column align="center" label="操作" width="250">
                  <template slot-scope="scope">
                    <el-button size="mini" class="bottom_all_two" @click="open('dialog2',scope.row)">协商调价</el-button>
                    <el-button size="mini" class="bottom_all_two" style="margin-left: 18px" @click="open('dialog3',scope.row)">调价记录</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div style="padding-top: 20px">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="fromDate03" tooltip-effect="dark">
                <el-table-column align="center" label="材料要求" prop="itemName"></el-table-column>
                <el-table-column align="center" label="预计量（方）">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.chargeStandard" type="Number" style="width:100%" @blur="save(scope.row)"></el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="初始合同价格">
                  <template slot-scope="scope">
                    <el-input 
                      v-model="scope.row.money"
                      v-input-limit="(value) => (String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/) ? String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/)[0] : '')" 
                      style="width:100%" 
                      type="Number" 
                      @blur="save(scope.row)">
                    </el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="备注" prop="remark">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.remark" style="width:100%" @blur="save(scope.row)"></el-input>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="最新调整价格" prop="newMoney"></el-table-column>
                <el-table-column align="center" label="操作" width="250">
                  <template slot-scope="scope">
                    <el-button size="mini" class="bottom_all_two" @click="open('dialog2',scope.row)">协商调价</el-button>
                    <el-button size="mini" class="bottom_all_two" style="margin-left: 18px" @click="open('dialog3',scope.row)">调价记录</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div style="padding-top: 20px">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="fromDate04" tooltip-effect="dark">
                <el-table-column align="center" label="特殊要求" prop="itemName"></el-table-column>
                <el-table-column align="center" label="预计量（方）">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.chargeStandard" type="Number" style="width:100%" @blur="save(scope.row)"></el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="初始合同价格">
                  <template slot-scope="scope">
                    <el-input 
                      v-model="scope.row.money"
                      v-input-limit="(value) => (String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/) ? String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/)[0] : '')" 
                      style="width:100%" 
                      type="Number" 
                      @blur="save(scope.row)">
                    </el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="备注" prop="remark">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.remark" style="width:100%" @blur="save(scope.row)"></el-input>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="最新调整价格" prop="newMoney"></el-table-column>
                <el-table-column align="center" label="操作" width="250">
                  <template slot-scope="scope">
                    <el-button size="mini" class="bottom_all_two" @click="open('dialog2',scope.row)">协商调价</el-button>
                    <el-button size="mini" class="bottom_all_two" style="margin-left: 18px" @click="open('dialog3',scope.row)">调价记录</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div style="padding-top: 20px">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="fromDate05" tooltip-effect="dark">
                <el-table-column align="center" label="外加剂要求" prop="itemName"></el-table-column>
                <el-table-column align="center" label="预计量（方）">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.chargeStandard" type="Number" style="width:100%" @blur="save(scope.row)"></el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="初始合同价格">
                  <template slot-scope="scope">
                    <el-input 
                      v-model="scope.row.money"
                      v-input-limit="(value) => (String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/) ? String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/)[0] : '')" 
                      style="width:100%" 
                      type="Number" 
                      @blur="save(scope.row)">
                    </el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="备注" prop="remark">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.remark" style="width:100%" @blur="save(scope.row)"></el-input>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="最新调整价格" prop="newMoney"></el-table-column>
                <el-table-column align="center" label="操作" width="250">
                  <template slot-scope="scope">
                    <el-button size="mini" class="bottom_all_two" @click="open('dialog2',scope.row)">协商调价</el-button>
                    <el-button size="mini" class="bottom_all_two" style="margin-left: 18px" @click="open('dialog3',scope.row)">调价记录</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div style="padding-top: 20px">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="fromDate06" tooltip-effect="dark">
                <el-table-column align="center" label="其他要求" prop="itemName"></el-table-column>
                <el-table-column align="center" label="预计量（方）">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.chargeStandard" type="Number" style="width:100%" @blur="save(scope.row)"></el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="初始合同价格">
                  <template slot-scope="scope">
                    <el-input 
                      v-model="scope.row.money"
                      v-input-limit="(value) => (String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/) ? String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/)[0] : '')" 
                      style="width:100%" 
                      type="Number" 
                      @blur="save(scope.row)">
                    </el-input>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="备注" prop="remark">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.remark" style="width:100%" @blur="save(scope.row)"></el-input>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="最新调整价格" prop="newMoney"></el-table-column>
                <el-table-column align="center" label="操作" width="250">
                  <template slot-scope="scope">
                    <el-button size="mini" class="bottom_all_two" @click="open('dialog2',scope.row)">协商调价</el-button>
                    <el-button size="mini" class="bottom_all_two" style="margin-left: 18px" @click="open('dialog3',scope.row)">调价记录</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
          <!-- 泵送费用 -->
          <div v-show="checkindex==1">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" border style="width: 100%" :data="fromDate1" tooltip-effect="dark">
              <el-table-column align="center" label="泵机类型" width="220" prop="itemName">
              </el-table-column>
              <el-table-column align="center" label="高度/臂长 (米)" width="550">
                <template slot-scope="scope">
                  <div v-for="(item,index) in scope.row.children" :key="index" class="divdiv">
                    <div>
                      <div v-if="index==0" class="itemdiv1">
                        <span style="padding:20px">小于</span>
                        <el-input v-model="item.chargeStandard[1]" type="Number" style="width:180px" @blur="scope.row.children[index+1].chargeStandard[0]=item.chargeStandard[1],save(item, 1,undefined,scope.row.children)"></el-input>
                        <el-button v-if="scope.row.children.length<2" size="mini" class="bottom_all" style="margin-left: 24px" @click="addfromDate1(scope.row,item,scope.row.children)">
                          <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
                          添加
                        </el-button>
                      </div>
                      <div v-else-if="index==(scope.row.children.length-1)" class="itemdiv1">
                        <span style="padding:20px">大于等于</span>
                        <el-input v-model="item.chargeStandard[0]" disabled type="Number" style="width:180px"></el-input>
                        <div>
                          <el-button size="mini" style="margin-left: 24px" class="bottom_two" @click="delfromDate1(scope.row,index,item)">
                            <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                            删除
                          </el-button>
                          <el-button v-if="scope.row.children.length>1" size="mini" class="bottom_all" style="margin-left: 12px" @click="addfromDate1(scope.row,item,scope.row.children)">
                            <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
                            添加
                          </el-button>
                        </div>
                      </div>
                      <div v-else class="itemdiv1">
                        <!-- <el-input v-model="scope.row.children[index-1].chargeStandard[1]" disabled style="width:100px"></el-input> -->
                        <el-input v-model="item.chargeStandard[0]" disabled style="width:100px"></el-input>
                        <span style="padding:20px">-</span>
                        <el-input v-model="item.chargeStandard[1]" type="Number" style="width:100px" @blur="scope.row.children[index+1].chargeStandard[0]=item.chargeStandard[1],save(item,1,undefined,scope.row.children)"></el-input>
                        <div>
                          <el-button size="mini" style="margin-left: 24px" class="bottom_two" @click="delfromDate1(scope.row,index,item)">
                            <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                            删除
                          </el-button>
                        </div>
                      </div>
                    </div>
                  </div>
                </template>
              </el-table-column>
              <el-table-column align="center" label="收费标准（元/方）">
                <template slot-scope="scope">
                  <div v-for="(item,index) in scope.row.children" :key="index" class="divdiv">
                    <div>
                      <el-input 
                        v-model="item.money" 
                        v-input-limit="(value) => (String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/) ? String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/)[0] : '')" 
                        type="Number" 
                        style="width:80px" 
                        @blur="save(item, 1, 2)"></el-input>
                      <el-button size="mini" class="bottom_all_two" style="margin-left: 12px" @click="open('dialog2',item)">调 价</el-button>
                      <el-button size="mini" class="bottom_all_two" style="margin-left: 12px" @click="open('dialog4',item)">查看记录</el-button>
                    </div>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset">关 闭</el-button>
      </span>
    </el-dialog>
    <!-- 信息调价 -->
    <el-dialog v-dialogDrag :visible.sync="dialog1" width="480px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">信息调价</span>
      <div class="dialoginfo">
        <el-form ref="low1" :rules="rules1" :inline="true" :model="low1" label-width="120px">
          <el-form-item prop="riskFactor">
            <span slot="label" style="color: #ff0000">风险系数：</span>
            <el-input v-model="low1.riskFactor" style="width:215px;" oninput="value=value>10?10:value" type="Number" placeholder="请输入" clearable>
              <template slot="append">%</template>
            </el-input>
          </el-form-item>
          <el-form-item prop="riskAmount">
            <span slot="label" style="color: #ff0000">风险金额：</span>
            <el-input 
              v-model="low1.riskAmount"
              v-input-limit="(value) => (String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/) ? String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/)[0] : '')" 
              oninput="value=value>50?50:value" 
              type="Number" 
              placeholder="请输入" 
              clearable>
            </el-input>
          </el-form-item>
          <el-form-item prop="adjustType">
            <span slot="label" style="color: #ff0000">选择调价类型：</span>
            <el-select v-model="low1.adjustType" placeholder="请选择">
              <el-option label="用砼当月信息价" :value="1"></el-option>
              <el-option label="用砼当期信息价" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="adjustBase">
            <span slot="label" style="color: #ff0000">选择调价基数：</span>
            <el-select v-model="low1.adjustBase" placeholder="请选择">
              <el-option label="按C30信息价" :value="1"></el-option>
              <el-option label="按标号信息价" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="adjustMethod">
            <span slot="label" style="color: #ff0000">选择调价方式：</span>
            <el-select v-model="low1.adjustMethod" placeholder="请选择">
              <el-option label="按风险系数" :value="1"></el-option>
              <el-option label="按风险金额" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="areaCode">
            <span slot="label" style="color: #ff0000">行政区：</span>
            <el-select v-model="low1.areaCode" placeholder="请选择">
              <el-option label="成都市区" value="1"></el-option>
              <el-option label="天府新区" value="2"></el-option>
              <el-option label="崇州市" value="3"></el-option>
              <el-option label="大邑县" value="4"></el-option>
              <el-option label="都江堰市" value="5"></el-option>
              <el-option label="金堂县" value="6"></el-option>
              <el-option label="龙泉驿区" value="7"></el-option>
              <el-option label="彭州市" value="8"></el-option>
              <el-option label="郫都区" value="9"></el-option>
              <el-option label="蒲江县" value="10"></el-option>
              <el-option label="邛崃市" value="11"></el-option>
              <el-option label="双流区" value="12"></el-option>
              <el-option label="温江区" value="13"></el-option>
              <el-option label="新都区" value="14"></el-option>
              <el-option label="新津区" value="15"></el-option>
              <el-option label="简阳市" value="16"></el-option>
              <el-option label="东部新区" value="17"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="autoAdjust">
            <span slot="label" style="color: #ff0000">自动调价：</span>
            <el-radio-group v-model="low1.autoAdjust">
              <el-radio :label="1">启用</el-radio>
              <el-radio :label="2">停用</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="dialog1=false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submit1">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 协商调价 -->
    <el-dialog v-dialogDrag :visible.sync="dialog2" width="800px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">协商调价</span>
      <div class="dialoginfo">
        <el-form ref="low2" :inline="true" :rules="rules2" :model="low2" label-width="110px">
          <div>
            <el-form-item v-if="low2.item==1" prop="code">
              <span slot="label">{{low2.itemType==1?'强度等级：':low2.itemType==2?'性能等级：':low2.itemType==3?'材料要求：':low2.itemType==4?'特殊要求：':low2.itemType==5?'外加剂要求：':'其他要求：'}}</span>
              <div>{{low2.itemName}}</div>
            </el-form-item>
            <el-form-item v-if="low2.item==2" prop="code">
              <span slot="label">泵机类型：</span>
              <div>{{low2.itemName}}</div>
            </el-form-item>
          </div>
          <div v-if="low2.item==2">
            <el-form-item prop="code">
              <span slot="label">高度/臂长：</span>
              <div>{{low2.chargeStandard[1]}}</div>
            </el-form-item>
          </div>
          <el-form-item prop="price">
            <span slot="label" style="color: #ff0000">调整价格：</span>
            <el-input 
              v-model="low2.price"
              v-input-limit="(value) => (String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/) ? String(value || '').match(/\d{1,6}(\.\d{1,2}|\.)?/)[0] : '')" 
              placeholder="请输入" 
              type="Number" 
              clearable></el-input>
          </el-form-item>
          <el-form-item prop="startTime">
            <span slot="label" style="color: #ff0000">生效日期：</span>
            <el-date-picker v-model="low2.startTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间">
            </el-date-picker>
          </el-form-item>
          <div style="padding-left: 42px;"><FileComponent2 fileCode="contractFile" :files="files2" @deleteFile="deleteFile2" @uplodeSuccess="uplodeSuccess2" /></div>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="dialog2=false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submit2">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 调价记录 -->
    <el-dialog v-dialogDrag :visible.sync="dialog3" width="880px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">调价记录</span>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="low3" tooltip-effect="dark">
          <el-table-column align="center" label="强度等级" prop="itemName"></el-table-column>
          <el-table-column align="center" label="调整价格" prop="price"></el-table-column>
          <el-table-column align="center" label="生效日期" prop="startTime"></el-table-column>
          <el-table-column align="center" label="调整时间" prop="createTime"></el-table-column>
          <el-table-column align="center" prop label="附件" width="120">
            <template slot-scope="scope">
              <el-button size="mini" class="bottom_all_two" @click="lookFile(scope)">查看</el-button>
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <el-button size="mini" class="bottom_two" @click="dellow3(scope.row,scope.$index)">
                <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="dialog3=false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 泵送调价记录 -->
    <el-dialog v-dialogDrag :visible.sync="dialog4" width="880px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">泵送调价记录</span>
      <div style="padding:10px 0;display:flex">
        <div>泵机类型： {{low2.itemName}}</div>
        <div v-if="dialog4" style="padding-left:40px">高度/臂长： {{low2.chargeStandard[1]}}</div>
      </div>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="low3" tooltip-effect="dark">
          <el-table-column align="center" label="调整价格" prop="price"></el-table-column>
          <el-table-column align="center" label="生效日期" prop="startTime"></el-table-column>
          <el-table-column align="center" prop label="附件" width="120">
            <template slot-scope="scope">
              <el-button size="mini" class="bottom_all_two" @click="lookFile(scope)">查看</el-button>
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <el-button size="mini" class="bottom_two" style="margin-left:24px" @click="dellow3(scope.row,scope.$index)">
                <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="dialog4=false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 查看附件 -->
    <LookFile :visible.sync="lookFileVisible" :config="lookFileConfig" />
  </div>
</template>
<script>
import FileComponent2 from '@/views/platform/ICPS/internetSales/components/fileComponent';
import LookFile from '@/components/File/LookFile';
// import { TreeSelect } from 'ant-design-vue';
import { queryPrising, savePrising, getDisClostDisAddCost, updateRevisePrice, getRevisePriceProduction, deleteRevisePrice, saveOrUpdateDisAddCost, getRevisePrice } from "@/api/internetSales/engineeringControl.js";
import { setTimeout } from 'timers';
let loading = false
export default {
  components: {
    // TreeSelect
    FileComponent2,
    LookFile
  },
  props: {
    dialog: {
      type: Boolean,
      default: false
    },
    low: {
      type: Object,
      default: new Object()
    }
  },
  data() {
    return {
      lookFileVisible: false,
      lookFileConfig: {},
      files2: [],
      checknavlist: [
        { name: '产品费用', id: 0 },
        { name: '泵送费用', id: 1 },
        { name: '小方量运输费用', id: 2 }
      ],
      checkindex: 0,
      fromDate2: {},
      fromDate1: [{ code: '', list: [{ code: '' }, { code: '' }, { code: '' }] }],
      fromDate01: [],
      fromDate02: [],
      fromDate03: [],
      fromDate04: [],
      fromDate05: [],
      fromDate06: [],
      dialog1: false,
      dialog2: false,
      dialog3: false,
      dialog4: false,
      dialog5: false,
      low1: {
        id: '',
        engineeringId: '',
        riskFactor: '',
        riskAmount: '',
        adjustType: 1,
        adjustBase: 1,
        adjustMethod: 1,
        autoAdjust: 1,
        // areaCode0: '',
        areaCode: '',
      },
      rules1: {
        riskFactor: [{ required: true, message: "请输入风险系数", trigger: "change" }],
        riskAmount: [{ required: true, message: "请输入风险金额", trigger: "change" }],
        adjustType: [{ required: true, message: "请选择调价类型", trigger: "change" }],
        adjustBase: [{ required: true, message: "请选择调价基数", trigger: "change" }],
        adjustMethod: [{ required: true, message: "请选择调价方式", trigger: "change" }],
        areaCode: [{ required: true, message: "请选择行政区", trigger: "change" }],
      },
      low2: {
        itemName: '',
        price: '',
        startTime: '',
        costId: '',
        itemType: 1
      },
      rules2: {
        price: [{ required: true, message: "请输入调整价格", trigger: "blur" }],
        startTime: [{ required: true, message: "请选择生效日期", trigger: "change" }],
      },
      low3: [],
      TreeSelectStypeNumber: 0,
    }
  },
  watch: {
    dialog() {
      if (this.dialog) {
        this.getAlldata()
      }
    },
  },
  methods: {
    lookFile({row}) {
      this.lookFileVisible = true;
      this.lookFileConfig = row;
    }, 
    uplodeSuccess2(data) {
      const params = {
        name: data.fileName,
        fileName: data.fileName,
        fileUrl: data.fileUrl,
        path: data.fileUrl,
        fileType: 1,
        type: 1,
        createTime: new Date().Format('yyyy-MM-dd hh:mm:ss'),
      }
      this.files2.push(params);
    },
    deleteFile2(index) {
      this.files2.splice(index, 1);
    },
    getAlldata() {
      getDisClostDisAddCost({ id: this.low.id }).then(res => {
        if (res.data) {
          let data = res.data.filter(res => (res.item == 2))
          const setArr = (item, cur) => {
            cur.chargeStandard = cur.chargeStandard ? cur.chargeStandard.split(',') : []
            if (item.some(res => (res.itemId == cur.itemId))) {
              item[item.findIndex(res => (res.itemId == cur.itemId))].children.push(cur)
            } else {
              let a = JSON.parse(JSON.stringify(cur))
              cur.children = [a]
              item.push(cur)
            }
            return item
          }
          let arr = data.reduce(setArr, [])
          this.fromDate1 = arr
          console.log(JSON.parse(JSON.stringify(this.fromDate1)))
          this.fromDate01 = res.data.filter(res => (res.item == 1 && res.itemType == 1)).map(item => ({ ...item, dataType: 2 }))
          this.fromDate02 = res.data.filter(res => (res.item == 1 && res.itemType == 2)).map(item => ({ ...item, dataType: 2 }))
          this.fromDate03 = res.data.filter(res => (res.item == 1 && res.itemType == 3)).map(item => ({ ...item, dataType: 2 }))
          this.fromDate04 = res.data.filter(res => (res.item == 1 && res.itemType == 4)).map(item => ({ ...item, dataType: 2 }))
          this.fromDate05 = res.data.filter(res => (res.item == 1 && res.itemType == 5)).map(item => ({ ...item, dataType: 2 }))
          this.fromDate06 = res.data.filter(res => (res.item == 1 && res.itemType == 6)).map(item => ({ ...item, dataType: 2 }))
          this.fromDate2 = res.data.find(res => (res.item == 3)) || {};
          this.fromDate2.dataType = 2;
        }
      })
    },
    reset() {
      this.$emit('reset', 'dialog1')
    },
    open(key, low) {
      if (key == "dialog1") {
        this.$data.low1 = this.$options.data().low1
        queryPrising({ engineeringId: this.low.id }).then(res => {
          if (res.data) {
            this.low1 = res.data
            console.log(this.low1);
            // console.log(this.low1.areaCode);
            // this.low1.areaCode0 = JSON.parse(this.low1.areaCode)[2]
          }
        })
        this[key] = true;
        setTimeout(() => {
          this.$refs.low1.clearValidate();
        }, 10)
        return
      }
      if (key == "dialog2") {
        this.low2.itemType = low.itemType
        this.low2.itemName = low.itemName
        this.low2.item = low.item
        this.low2.chargeStandard = low.chargeStandard
        this.low2.price = ''
        this.low2.startTime = ''
        this.low2.costId = low.id
        this[key] = true;
        setTimeout(() => {
          this.$refs.low2.clearValidate();
        }, 10)
        return
      }
      if (key == "dialog3") {
        getRevisePriceProduction({ engineeringId: this.low.id, itemId: low.itemId }).then(res => {
          this.low3 = res.data.data
        })
        this[key] = true;
        return
      }
      if (key == "dialog4") {
        this.low2.itemName = low.itemName
        this.low2.chargeStandard = low.chargeStandard
        getRevisePrice({ costId: low.id }).then(res => {
          this.low3 = res.data.data
        })
        this[key] = true;
        return
      }
    },
    /**泵送费用*/
    addfromDate1(low, item, list) {
      if (loading) {
        return
      }
      loading = true
      console.log(JSON.parse(JSON.stringify(item)))
      let num = item.chargeStandard[1],
        chargeStandardArr = []
      if (list.length >= 2) {
        num = item.chargeStandard[0]
        item.chargeStandard[1] = String(Number(num) + 1)
        chargeStandardArr = [String(Number(num) + 1), '99999999']
        console.log(item.chargeStandard);
      } else {
        chargeStandardArr = [num, '99999999']
      }
      console.log(chargeStandardArr);
      const data = {
        dataType: 1,
        chargeStandard: chargeStandardArr,
        engineeringId: low.engineeringId,
        item: low.item,
        itemId: low.itemId,
        itemName: low.itemName,
        itemType: low.itemType,
        money: 0,
      }
      low.children.push(data)
      let arrList = JSON.parse(JSON.stringify(this.fromDate1))
      let arrData = []
      arrList.forEach((v) => {
        arrData = [...arrData, ...v.children]
      })
      arrData.forEach((v, k) => {
        v.chargeStandard = v.chargeStandard.join(',')
        v.sortNum = k
      })
      saveOrUpdateDisAddCost(arrData).then(res => {
        loading = false
        if (res.code == 1001) {
          this.getAlldata()
          // console.log(JSON.parse(JSON.stringify(low.children)))
        }
      })
    },
    delfromDate1(low, index, del) {
      let deldata = JSON.parse(JSON.stringify(del))
      deldata.dataType = 0
      console.log(JSON.parse(JSON.stringify(deldata)))
      deldata.chargeStandard = deldata.chargeStandard.join(',')
      saveOrUpdateDisAddCost([deldata]).then(res => {
        if (res.code == 1001) {
          low.children.splice(index, 1)
        }
      })

    },
    administrativeDistrictsFun(value, label, extra) {
      console.log(value, label, extra);//区id和名字
      // console.log(extra.triggerNode.$parent.$options.propsData.title);//县名
      // console.log(extra.triggerNode.$parent.$options.propsData.value);//县id
      // console.log(extra.triggerNode.$parent.$parent.$options.propsData.title);//市名
      // console.log(extra.triggerNode.$parent.$parent.$options.propsData.value);//市id
      // this.low1.areaCode = JSON.stringify([extra.triggerNode.$parent.$parent.$options.propsData.value, extra.triggerNode.$parent.$options.propsData.value, value])
      this.$forceUpdate()
    },
    /**信息调价*/
    submit1() {
      this.$refs.low1.validate((valid) => {
        if (valid) {
          const params = { ... this.low1, engineeringId: this.low.id }
          savePrising(params).then(res => {
            if (res.code == 1001) {
              this.$message({
                message: '保存成功',
                type: "success",
              });
              this.dialog1 = false
            }
          })
        } else {
          return false;
        }
      });
    },
    /**协商调价*/
    submit2() {
      if(!this.files2?.length) {
        return this.$message.warning("请上传附件文件")
      }
      this.$refs.low2.validate((valid) => {
        if (valid) {
          const params = {
            costId: this.low2.costId, 
            price: this.low2.price, 
            startTime: this.low2.startTime,
            filePaths: JSON.stringify(this.files2)
          }
          updateRevisePrice([params]).then(res => {
            if (res.code == 1001) {
              this.$message({
                message: '保存成功',
                type: "success",
              });
              this.dialog2 = false
              this.getAlldata()
            }
          })
        } else {
          return false;
        }
      });
    },
    /**删除调价记录*/
    dellow3(low, index) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'bottom_all_two',
        confirmButtonClass: 'bottom_all',
        type: 'warning'
      }).then(() => {
        deleteRevisePrice({ id: low.id }).then(res => {
          if (res.code == 1001) {
            this.$message({
              message: '删除成功',
              type: "success",
            });
            this.low3.splice(index, 1)
          }
        })

      }).catch(() => {

      });
    },
    /**保存修改信息*/
    save(row, type, dataType, indexList) {
      setTimeout(() => {
        console.log(row, type, dataType, indexList);
        let arrData = []
        if (type == 1 || type == 2) {
          let params = JSON.parse(JSON.stringify(row))
          if (type === 1) {
            params.chargeStandard[0] = 0;
          }
          if (type === 2) {
            params.chargeStandard[1] = 99999999;
          }
          if (params.item == 2) {
            params.chargeStandard = params.chargeStandard.join(',')
          }
          params.dataType = dataType || params.dataType;
          console.log(JSON.parse(JSON.stringify(params)))
          // 验证--------开始
          var arr1 = []
          if (indexList) {
            arr1 = JSON.parse(JSON.stringify(indexList))
          }
          let type1 = false
          if (arr1.length >= 3) {
            arr1.forEach((v, k) => {
              if (k > 0 && k < arr1.length - 1 && v.chargeStandard[1] - arr1[k - 1].chargeStandard[1] <= 0) {
                type1 = true
              }
            })
          }
          if (type1) {
            this.$message({
              message: '区间值范围不正确，请检查！',
              type: 'warning'
            });
            return
          }
          // 验证--------结束
          if (!params.dataType) {
            params.dataType = 1;
          }
          let arrList = JSON.parse(JSON.stringify(this.fromDate1))
          arrList.forEach((v) => {
            arrData = [...arrData, ...v.children]
          })
          arrData.forEach((v, k) => {
            v.chargeStandard = v.chargeStandard.join(',')
            v.sortNum = k
          })
          console.log(JSON.parse(JSON.stringify(arrData)))
        } else if (type == 3) {
          arrData = [this.fromDate2]
        } else {
          arrData = [row]
        }
        saveOrUpdateDisAddCost(arrData).then((res) => {
          if (res.code == 1001) {
            this.getAlldata()
          }
        })
      }, 100)
    },
    TreeSelectStypeFun() {
      if (this.TreeSelectStypeNumber === 0) {
        this.TreeSelectStypeNumber = 1;
        setTimeout(() => {
          const dom = document.body.lastChild;
          dom.style.zIndex = '10000'
        }, 1000)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.divdiv {
  height: 52px;
  padding-left: 50px;
  display: flex;
  align-items: center;
}
.divdiv + .divdiv {
  border-top: 1px solid #dcdfe6;
}
.itemdiv1 {
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
